package com.hnevc.exam4zhangsan;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class ShowActivity extends AppCompatActivity {
    List<Food> foodList;
    //定义控件变量mListView
    ListView mListView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        //TODO 功能实现题：获取数据并更新界面

    }
    //定义适配器对类型
    class MyBaseAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return foodList.size();
        }

        @Override
        public Object getItem(int position) {
            return foodList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return foodList.get(position).getFoodId();
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            //根据项目布局，获取视图对象
            convertView = LayoutInflater.from(ShowActivity.this)
                    .inflate(R.layout.list_item,null);
            //从刚才获取的视图对象中，获取显示食物名称的TextView
            TextView mTvFoodName = (TextView) convertView.findViewById(R.id.id_tv_foodname);
            //将mTvFoodName控件所显示的文字，设置为position位置的食物的名字
            mTvFoodName.setText(foodList.get(position).getFoodName());
            //TODO 功能实现2 显示食物的详细信息

            //返回获取到的视图
            return convertView;
        }
    }
}
